package com.team.book.common.domain;

import java.util.ArrayList;
import java.util.List;

/**
 * @author iw
 * @create 2017-05-08 11:15
 **/
public class Page<T> {

    protected int pageNo = 1;
    protected int offset = 0;
    protected int pageSize = 10;

    protected long totalCount = 0;
    protected int totalPage = 1;


    protected List<T> result = new ArrayList<T>();

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
        this.setTotalPage();
    }

    public long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
        this.setTotalPage();
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public List<T> getResult() {
        return result;
    }

    public void setResult(List<T> result) {
        this.result = result;
    }

    private void setTotalPage(){
        if(totalCount>0){
            this.totalPage = (int)(totalCount/pageSize);
            long num = totalCount%pageSize;
            if(num>0){
                ++this.totalPage;
            }
        }
    }

    public int getOffset() {
        if(pageNo>1){
            this.offset = (pageNo-1)*pageSize;
        }
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }
}
